<?php


namespace app\merchant\system\controller;

use support\utils\RandomUtil;

/**
 * Class UploadController
 * @package app\merchant\system\controller
 */
class UploadController extends BaseController
{
    public function uploadFile()
    {
        $file = request()->file("file");
        $folderName = input("folderName", "default");
        $date = date("Ymd");
        $uuid = RandomUtil::UUID();
        $path = "/upload/{$folderName}/{$date}/{$uuid}" . "." . $file->getUploadExtension();
        $filePath = public_path() . $path;
        if ($file && $file->isValid()) {
            $file->move($filePath);
        }
        return $this->success([
            'fileUploadPath' => "//" . request()->host() . $path
        ]);
    }
}